<?php
header('Content-Type:application/json;charset=UTF-8');
$conn = mysqli_connect('localhost', 'root', 'root', 'echarts');
if (!$conn) {
    echo json_encode(['code' => 0, 'msg' => '数据库连接失败']);
}
$sql1 = "select count(*) as sex1 from user where sex = 0";
$sql2 = "select count(*) as sex2 from user where sex = 1";
$query1 = mysqli_query($conn, $sql1);
$query2 = mysqli_query($conn, $sql2);
$result1 = mysqli_fetch_assoc($query1);
$result2 = mysqli_fetch_assoc($query2);
$data = [
    ['value'=>$result1['sex1'],'name'=>"男生"],
    ['value'=>$result2['sex2'],'name'=>"女生"],
];
echo json_encode(['code' => 1, 'msg' => '员工性别比例', 'data' => $data]);
